package pers.cz.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pers.cz.mapper.AutoUiTestCaseMapper;
import pers.cz.model.AutoUiTestCase;
import pers.cz.mybatisPlugin.PageRowBounds;
import pers.cz.pub.BeanHelper;
import pers.cz.pub.CpublicFunc;
import pers.cz.pub.SequenceEnum;
import pers.cz.service.AutoUiTestCaseService;

import java.util.Date;
import java.util.List;

/**
 * @program: PostGirl-panent
 * @description:
 * @author: Cheng Zhi
 * @create: 2023-01-26 17:36
 **/
@Service
public class AutoUiTestCaseServiceImpl implements AutoUiTestCaseService {

    @Autowired
    BeanHelper beanHelper;

    @Override
    public List<AutoUiTestCase> queryAll() {

        // 为了提升效率，这里只是查询出的内容不包含maxgraph的xml内容，具体展示的时候在单独查询。
        return beanHelper.getBean(AutoUiTestCaseMapper.class).queryAll();
    }

    @Override
    public Integer queryCount() {
        return beanHelper.getBean(AutoUiTestCaseMapper.class).queryCount();
    }

    @Override
    public List<AutoUiTestCase> queryByPage(Integer start, Integer limit) {
        PageRowBounds pageRowBounds = new PageRowBounds(start, limit);
        return beanHelper.getBean(AutoUiTestCaseMapper.class).queryByPage(pageRowBounds);
    }

    @Override
    public String queryCfgByFlowId(Integer flowId) {
        return beanHelper.getBean(AutoUiTestCaseMapper.class).queryCfgByFlowId(flowId);
    }


    @Override
    public Integer save(AutoUiTestCase autoUiTestCase) {

        CpublicFunc cPublicFunc = new CpublicFunc(beanHelper);
        Long soNbr = cPublicFunc.getSoNbr(SequenceEnum.AUTO_UI_TESTCASE);
        autoUiTestCase.setFlowId(soNbr);
        autoUiTestCase.setCreateTime(new Date());
        autoUiTestCase.setUpdateTime(new Date());
        int i = beanHelper.getBean(AutoUiTestCaseMapper.class).insertSelective(autoUiTestCase);
        return i;
    }

    @Override
    public Integer modify(AutoUiTestCase autoUiTestCase) {

        autoUiTestCase.setUpdateTime(new Date());
        int i = beanHelper.getBean(AutoUiTestCaseMapper.class).updateByPrimaryKeySelective(autoUiTestCase);
        return i;
    }

    @Override
    public Integer delete(AutoUiTestCase autoUiTestCase) {

        Long flowId = autoUiTestCase.getFlowId();
        int i = beanHelper.getBean(AutoUiTestCaseMapper.class).deleteByPrimaryKey(flowId);
        return i;
    }
}
